package object.obj2D.tree;

import java.util.Random;

import object.obj2D.graphics.Texture;

import com.game.R;

public class Trees {
	private float[] m_angle;
	private float[] m_distanceZ;
	private float[] m_distanceY;
	private int[] m_textureID;
	private int m_iNumOfTrees;
	private static final int NUM_OF_TREE_TYPE = 3;
	private Tree m_tree;
	
	public Trees(int numOfTrees)
	{
		m_iNumOfTrees = numOfTrees;
		if(m_iNumOfTrees <= 0) m_iNumOfTrees = 1;
		InitTree();
	}
	
	private static final int NUM_OF_TREE = 12;
	
	private void InitTree()
	{
		int[] m_treeTexID = new int[NUM_OF_TREE_TYPE];
		
		Texture m_texture = new Texture();
		m_treeTexID[0] = m_texture.initTexture(R.drawable.tree1);
		m_treeTexID[1] = m_texture.initTexture(R.drawable.tree2);
		m_treeTexID[2] = m_texture.initTexture(R.drawable.tree3);

		
		m_angle = new float[m_iNumOfTrees];
		m_distanceZ = new float[m_iNumOfTrees];
		m_distanceY = new float[m_iNumOfTrees];
		m_textureID = new int[m_iNumOfTrees];
		m_tree = new Tree(4, 4);
		
		Random r = new Random();
		for(int i = 0; i < NUM_OF_TREE; ++i)
		{
			m_textureID[i] = m_treeTexID[r.nextInt(3)];
			m_angle[i] = r.nextInt(361);
			m_distanceY[i] = -1f;
			m_distanceZ[i] = r.nextInt(16) + 10;
		}
	}
	
	public void Render()
	{
		for(int i = 0; i < m_iNumOfTrees; ++i)
		{
			m_tree.SetTexID(m_textureID[i]);
			m_tree.SetAngle(m_angle[i]);
			m_tree.SetDistanceY(m_distanceY[i]);
			m_tree.SetDistanceZ(m_distanceZ[i]);
			m_tree.Render();
		}
	}
}
